package com.ics.atable.chat.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MybatisPlusConfig {

	@Bean
	public MybatisPlusInterceptor mybatisPlusInterceptor() {
		MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();

		// 分页插件
		PaginationInnerInterceptor paginationInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);

		// 设置请求的页码超过最大页后，自动返回首页（true），而不是返回空数据
		paginationInterceptor.setOverflow(true);

		// 设置单页最大数量限制，避免恶意传入超大 pageSize 拖垮数据库
		paginationInterceptor.setMaxLimit(50L);

		interceptor.addInnerInterceptor(paginationInterceptor);
		return interceptor;
	}
}
